package com.cj.service.impl;

import com.cj.dao.ClassDao;
import com.cj.po.Classes;
import com.cj.po.PageInfo;
import com.cj.po.Student;
import com.cj.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("classService")
@Transactional
public class ClassServiceImpl implements ClassService {
    @Autowired
    private ClassDao classDao;

    @Override
    public PageInfo<Classes> findPageInfo(Integer c_classid, String c_classname, String c_counsellor,
                                          Integer pageIndex, Integer pageSize) {
        PageInfo<Classes> ci = new PageInfo<Classes>();
        ci.setPageIndex(pageIndex);
        ci.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = classDao.totalCount1(c_classid,c_classname,c_counsellor);
        if (totalCount>0){
            ci.setTotalCount(totalCount);
            //每一页显示学生信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Classes> classList =    classDao.getClassList(c_classid,c_classname,c_counsellor,
                    (ci.getPageIndex()-1)*ci.getPageSize(),ci.getPageSize());
            ci.setList(classList);
        }
        return ci;
    }

    @Override
    public List<Classes> getAll() {
        List<Classes> classList = classDao.getAll();
        return classList;
    }

    @Override
    public Classes findClassById(Integer c_id) {
        return classDao.findClassById(c_id);
    }

    @Override
    public int deleteClass(Integer c_id) {
        return classDao.deleteClass(c_id);
    }

    @Override
    public int addClass(Classes classes) {
        return classDao.addClass(classes);
    }

    @Override
    public int updateClass(Classes classes) {
        return classDao.updateClass(classes);
    }

    @Override
    public List<Classes> getClassAndStudent() {
        return classDao.getClassAndStudent();
    }


}
